//
//  FkfsView.m
//  EasyToTesco
//
//  Created by mc on 16/3/4.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "FkfsView.h"

#define fkfsMarc 5

@interface FkfsView()
{
    UIView *firstview;
    UIView *secondView;
    
    
    UILabel *firstlabel;
    UILabel *secondLable;
    
}


@end


@implementation FkfsView


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.userInteractionEnabled = YES;
        [self addFkfsUI];
    }
    return self;
}


- (void)addFkfsUI {
    CGFloat weith = CGRectGetWidth(self.frame);
    CGFloat heigh = CGRectGetHeight(self.frame);
    
    
    self.titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(fkfsMarc, fkfsMarc, weith-fkfsMarc*5, heigh/3-fkfsMarc*2)];
    self.titlelabel.font = [UIFont systemFontOfSize:12];
    self.titlelabel.textAlignment = NSTextAlignmentLeft;
    self.titlelabel.textColor = [UIColor blackColor];
    [self addSubview:self.titlelabel];
    
    firstview = [[UIView alloc] initWithFrame:CGRectMake(weith/4-10, ((heigh/3)*2)-5, 10, 10)];
    firstview.layer.borderWidth = 1;
    firstview.layer.borderColor = [UIColor grayColor].CGColor;
    firstview.layer.cornerRadius = CGRectGetHeight(firstview.frame)/2;
    firstview.layer.masksToBounds = YES;
    firstview.backgroundColor = [UIColor greenColor];
    [self addSubview:firstview];
    
    
    firstlabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(firstview.frame), ((heigh/3)*2)-15/2, weith/4, 15)];
    firstlabel.text = @"余额支付";
    firstlabel.font = [UIFont systemFontOfSize:12];
    firstlabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:firstlabel];
    
    
    secondView = [[UIView alloc] initWithFrame:CGRectMake((weith/4)*3-10, ((heigh/3)*2)-5, 10, 10)];
    secondView.layer.borderWidth = 1;
    secondView.layer.cornerRadius = CGRectGetHeight(secondView.frame)/2;
    secondView.layer.masksToBounds = YES;
    
    secondView.layer.borderColor = [UIColor grayColor].CGColor;
    [self addSubview:secondView];
    
    secondLable = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(secondView.frame), ((heigh/3)*2)-15/2, weith/4, 15)];
    secondLable.text = @"积分支付";
    secondLable.font = [UIFont systemFontOfSize:12];
    secondLable.textAlignment = NSTextAlignmentLeft;
    [self addSubview:secondLable];
    
    for (NSInteger i=0; i<2; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake((weith/2)*i, heigh/3, weith/2, (heigh/3)*2);
        button.tag = 890+i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
    }
    
    
    
}

- (void)buttonClick:(UIButton *)button {
    [self.delegate fkfsViewBtnClick:button];
    if (button.tag == 890) {
        firstview.backgroundColor = [UIColor greenColor];
        secondView.backgroundColor = [UIColor whiteColor];
    } else {
        secondView.backgroundColor = [UIColor greenColor];
        firstview.backgroundColor = [UIColor whiteColor];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
